from rest_framework import serializers

from areas.models import Area


class AreaSerializer(serializers.ModelSerializer):
    """行政区划序列化器"""

    class Meta:
        model = Area
        fields = ['id', 'name']


class AreasSerializer(serializers.ModelSerializer):
    """子行政区划序列化器（市区）"""
    # 得到行政区的id name字段
    subs = AreaSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']
